{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Voronoi Diagrams"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*scikit-geometry* comes with methods to efficiently compute the voronoi diagram of points."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from skgeom import *\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "npoints = np.random.rand(100, 2) * 20 - 10\n",
    "points = []\n",
    "for r in npoints:\n",
    "    points.append(Point2(*r))\n",
    "\n",
    "vdiag = voronoi.VoronoiDiagram()\n",
    "\n",
    "for p in points:\n",
    "    vdiag.insert(p)\n",
    "\n",
    "for he in vdiag.edges:\n",
    "    source, target = he.source(), he.target()\n",
    "    if source and target:\n",
    "        plt.plot([source.point().x(), target.point().x()], [source.point().y(), target.point().y()])\n",
    "\n",
    "plt.scatter(npoints[:, 0], npoints[:, 1])\n",
    "\n",
    "plt.axis('equal')\n",
    "plt.gca().set_adjustable(\"box\")\n",
    "plt.gca().set_xlim([-10, 10])\n",
    "plt.gca().set_ylim([-10, 10])\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
